package grum

class GroupWebTests extends grails.util.WebTest {
    void testGroupList() {
		invoke      'group/list'
		verifyTitle  'Group List'
		verifyText  'Group List'
	
		verifyListSize 3
    }

    void testGroupNewEditDelete() {
		invoke      '/group/index'
		group(description:'login as admin') {
		  clickLink "login"
		  setInputField(name: "username", value: "admin")
		  setInputField(description: "Set password field password: adm123", name: "password", value: "adm123")
		  clickButton "Login"
	
		  verifyText 'login successful.'
		}
	
		invoke      'group/index'
		group(description:'create a new Group') {
		  clickLink "ADD NEW"
	
		  verifyTitle  'Create Group'
		  verifyText  'Create Group'
		  
		  setInputField(name: "name", value: "juhu")
		  clickButton "Create"
	
		  verifyXPath xpath:  "//div[@class='box']",
			      text:   /.*Group.*created.*/,
			      regex:  true
		}
	
		group(description:'edit a Group') {
		  clickButton "Edit"
		  setInputField(name: "name", value: "joho")
		  clickButton "Update"
	
		  verifyXPath xpath:  "//div[@class='box']",
			      text:   /.*Group.*updated.*/,
			      regex:  true
		}
	
		group(description:'delete a Group') {
		  clickButton 'Delete'
	
		  verifyXPath xpath:  "//div[@class='box']",
			      text:   /.*Group.*deleted.*/,
			      regex:  true
		}
    }

    String ROW_COUNT_XPATH = "count(//table[@class='listing']//tbody/tr)"

    void verifyListSize(int size) {
        ant.group(description:"verify Group list view with $size row(s)") {
            verifyText  'Group List'
            verifyXPath xpath:      ROW_COUNT_XPATH,
                        text:       size,
                        description:"$size row(s) of data expected"
        }
    }
}
